package com.aaa.javaweb.dao.impl;

import com.aaa.javaweb.dao.DeptDao;
import com.aaa.javaweb.entity.Dept;
import com.aaa.javaweb.until.JDBCUntil;

import java.util.List;
import java.util.Map;

public class DeptDaoImpl implements DeptDao {

    @Override
    public List<Map> queryAll() {
        String sql="select * from t_departtable";
        List<Map> maps = JDBCUntil.selectMap(sql);
        return maps;
    }

    @Override
    public int delGust(String gid) {
        String sql="delete from t_departtable where id=?";
        return JDBCUntil.Updateout(sql,gid);
    }

    @Override
    public int add(Dept g) {
        if(g.getId()==null){
            String sql="insert into t_departtable(dname) values(?)";
            System.out.println(sql);
            return JDBCUntil.Updateout(sql,g.getDname());
        }else{
            String sql="update t_departtable set dname=? where id=?";
            return JDBCUntil.Updateout(sql,g.getDname(),g.getId());
        }
    }

    @Override
    public Map findGustById(String gid) {
        String sql="select * from t_departtable where id=?";
        List<Map> maps = JDBCUntil.selectMap(sql, gid);//
        //
        Map m=maps.get(0);
        return m;
    }
}
